<template>
  <div class="text-content">
    <h1 class="title">{{ dateTime }}</h1>
    <h2 class="sub-title">{{ date }}</h2>
    <h2 class="sub-title">{{ dateChinese }}</h2>
    <h1>Welcome to <span class="text-gradient">{{ city }}</span></h1>
    <div class="weather">
      <weather :dayWeather="dayWeatherList"></weather>
    </div>
  </div>
</template>

<script setup>
  import {defineProps, ref, onUnmounted} from 'vue'
  import weather from './Weather.vue'
  import chinese from 'chinese-lunar'

  const dayArr = ['日','一', '二', '三', '四', '五', '六']
  const props = defineProps({title: String, dayWeather: Object})
  let dateTime = ref('')
  let date = ref('')
  let dateChinese = ref('')
  let city = '北京'
  const dayWeatherList = props.dayWeather
  // const dayWeather = dayWeatherList.slice(0, 5)

  function time() {
    const date = new Date()
    const YY = date.getFullYear()
    const MM = date.getMonth()
    const DD = date.getDate()
    const hh = date.getHours()
    const mm = date.getMinutes()
    const ss = date.getSeconds()
    const day = date.getDay()
    return {
      chinese: `${YY}-${MM+1}-${DD}`,
      date: `${YY} - ${MM > 9 ? MM+1 : `0${MM+1}`} - ${DD > 9 ? DD : `0${DD}`}`,
      time: `${hh > 9 ? hh : `0${hh}`} : ${mm > 9 ? mm : `0${mm}`} : ${ss > 9 ? ss : `0${ss}`}`,
      day
    }
  }
  dateTime.value = time().time
  date.value = time().date + ' 星期' +dayArr[time().day]
  dateChinese.value = chinese.solarToLunar(new Date(time().chinese), 'T A MD')

  let timer = setInterval(() => {
    dateTime.value = time().time
    // date.value = time().date + ' 星期' +dayArr[time().day]
  }, 1000)
  onUnmounted(() => {
    clearInterval(timer)
  })
</script>

<style scoped>
  .text-content {
    position: fixed;
    width: 100%;
    height: 100%;
    z-index: 5;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }
  h1 {
    font-size: 3rem;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    color: #fff;
  }
  .sub-title {
    font-size: 2rem;
    line-height: 1;
  }
  .text-gradient {
    background-image: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-size: 400%;
    background-position: 0%;
    font-size: 6rem;
  }
</style>
